/**
 * 提供公共下拉组件
 */
layui.define(['zmnOmsXmSelect'], function (exports) {
    let $ = layui.$,
        xmSelect = layui.zmnOmsXmSelect,
        zmnSelectCache = {};

    /**
     * 获取合并后的对象
     * @param source
     * @param defaultSource
     * @param target
     * @return {*}
     */
    function getMergedObj(source, defaultSource, target) {
        source = zmnUtil.isObject(source) ? source : {};
        target = zmnUtil.isObject(target) ? target : {};
        return $.extend(true, target, defaultSource, source);
    }

    /**
     * 获取指定属性
     * @param obj 对象
     * @param fieldLink 属性路径
     * @param defaultValue 默认值
     * @return {*}
     */
    function getField(obj, fieldLink, defaultValue) {
        if (!zmnUtil.isObject(obj)) {
            return defaultValue;
        }
        let links = fieldLink.split('.');
        for (let link of links) {
            let result = link in obj;
            if (result === false) {
                return defaultValue;
            }
            obj = obj[link];
        }
        return obj;
    }

    /**
     * 数组去重
     * @param array
     * @param propMap
     * @return {[]}
     */
    function uniqueArray(array, propMap) {
        let result = [];
        let obj = {};
        for (let i = 0, len = array.length; i < len; i++) {
            let key = array[i][propMap.value];
            if (!obj[key]) {
                result.push(array[i]);
                obj[key] = true;
            }
        }
        return result;
    }

    /**
     * 比较数组
     * @param arr1
     * @param arr2
     * @return {boolean}
     */
    function compareArray(arr1, arr2) {
        return JSON.stringify(arr1) == JSON.stringify(arr2);
    }

    /**
     * 为兼容旧业务的公司类型
     * @param oldType 旧业务的公司类型
     * @return {[]}
     */
    function convertCompanyType(oldType) {
        let types = [];
        if (zmnUtil.isNotInteger(oldType)) {
            return types;
        }
        oldType = parseInt(oldType);
        switch (oldType) {
            case 10:
                types.push({
                    type: 130, //公司类型：服务商
                    childType: 10, //公司子类型：信息公司
                });
                types.push({
                    type: 130, //公司类型：服务商
                    childType: 20,//非直营
                });
                break;
            case 11:
                types.push({
                    type: 130, //公司类型：服务商
                    childType: 10, //公司子类型：信息公司
                });
                break;
            case 12:
                types.push({
                    type: 130, //公司类型：服务商
                    childType: 20,//非直营
                });
                break;
            case 20:
                types.push({
                    type: 130, //公司类型：服务商
                    childType: 10, //公司子类型：信息公司
                });
                types.push({
                    type: 140, //公司类型：电器公司
                    childType: 10, //电器公司
                });
                break;
            case 21:
                types.push({
                    type: 140, //公司类型：电器公司
                    childType: 10, //电器公司
                });
                break;
        }
        return types;
    }

    //api网关地址
    let GATEWAY_API_BASE = ZMN_CONFIG.BASE_URL.GATEWAY_API_BASE;

    //默认的基础配置
    let defaultBasicOptions = {
        name: null, //表单提交时的name
        isReload: true, //初始化时，是否重载数据
        tips: "-选择-",   //默认提示
        searchTips: "请选择", //
        emptyTips: "没有找到相关结果",  //空值提示
        isRadio: false, //单选标识：true-单选；false-多选
        filterable: true, //是否开启搜索
        autoRow: true, //选择值换行
        showCount: 1, //选择值展示个数
        maxCount: 50, //下拉框中的最多选项数量
        sizeModel: "mini", //尺寸模式：medium；small；mini
        propMap: {  //选项参数映射配置
            name: "text",   //显示值
            value: "value"  //选中值
        },
        page: { //分配配置
            enable: false,  //开关：true-开启；false-关闭
            pageSize: 30,   //页数
            isShowEmpty: false, //无数据时是否显示分页
            remote: false, //远程分页开关：true-开启；false-关闭
        },
        tree: {
            //是否显示树状结构
            enable: false,
            //是否展示三角图标
            showFolderIcon: true,
            //是否显示虚线
            showLine: true,
            //间距
            indent: 20,
            //是否严格遵守父子模式
            strict: true,
            //默认展开节点的数组, 为 true 时, 展开所有节点
            expandedKeys: [],
            //懒加载开关
            lazy: false,
            events: {
                load: function (item, callback) {
                }
            }
        },
        events: {  //事件配置
            /**
             * 选择中事件
             * @param values 已选中值，Array类型
             */
            changing: function (values) {
            },
            /**
             * 选择完成后事件
             * @param values 已选中值，Array类型
             */
            changed: function (values) {
            },
            /**
             * 重载判断事件
             */
            reload: function (options) {
                return options.isReload;
            }
        },
    }

    //默认的数据源配置
    let defaultDataSourceOptions = {
        data: [], //静态下拉数据
        searchedValue: null, //已搜索值（用于回显）
        selectedValues: [], //已选中值（用于回显)
        remote: { //远程获取下拉数据
            enable: false, //开关：true-开启；false-关闭
            search: false, //自动请求标识：true-初始化完成后自动请求；false-不自动请求
            delay: 800, //搜索延迟（毫秒）
            method: 'post',
            body: true,
            url: null, //服务url
            limitPermit: false, //权限校验标识：true-校验；false-不校验
            events: { //事件配置
                /**
                 * 校验搜索值格式
                 * @param searchValue 搜索值
                 * @return {*|boolean}
                 */
                validate: function (searchValue) {
                    return true;
                },
                /**
                 * 扩展请求参数
                 * @param prevValues 上一级下拉框已选中的值数组（级联下拉框时有效）
                 * @param newExtendParams 自定义的扩展请求参数
                 * @return {{}}
                 */
                extendParams: function (prevValues, newExtendParams) {
                    return {}
                },
                /**
                 * 组装请求参数
                 * @param searchValue 搜索值
                 * @param limitPermit 权限校验标识
                 * @return {{limitPermit: boolean, keyword: *}}
                 */
                params: function (searchValue, limitPermit, pageIndex) {
                    return {
                        keyword: searchValue,
                        limitPermit: limitPermit === true,
                    }
                },
                /**
                 * 请求成功回调
                 * @param result 响应结果
                 * @param callback xmSelect回调函数
                 */
                success: function (result, callback, dataMap) {
                    let res = result.data;
                    let dm = (result.status == 200 || res.status == 200) ? dataMap(res) : {data: []}
                    if (zmnUtil.isInteger(dm.pageCount)) {
                        callback(dm.data, dm.pageCount);
                    } else {
                        callback(dm.data);
                    }
                },
                /**
                 * 请求异常回调
                 * @param error 异常信息
                 */
                error: function (error) {
                    console.log(error);
                },
                /**
                 * 数据映射
                 * @param result  响应结果
                 */
                dataMap: function (resultData) {
                    return {
                        data: resultData.data
                    };
                }
            }
        },
    }

    let zmnSelect = {
        options: getMergedObj(defaultBasicOptions, defaultDataSourceOptions),
        /**
         * 合并自定义配置和默认配置
         * @param selectId
         * @param options
         * @param defaultOptions
         * @return {*}
         */
        mergeOptions: function (selectId, options, defaultOptions) {
            options = zmnUtil.isObject(options) ? options : {};
            defaultOptions = zmnUtil.isObject(defaultOptions) ? defaultOptions : {};
            let extendParamsEvent = getField(options, "remote.events.extendParams");
            if (zmnUtil.isFunction(extendParamsEvent)) {
                this.updateExtendParamsEvent(selectId, extendParamsEvent);
                delete options.remote.events.extendParams;
            }
            let defaultExtendParamsEvent = getField(defaultOptions, "remote.events.extendParams");
            if (zmnUtil.isFunction(defaultExtendParamsEvent)) {
                this.updateDefaultExtendParamsEvent(selectId, defaultExtendParamsEvent);
                delete defaultOptions.remote.events.extendParams;
            }
            let newOptions = getMergedObj(options, defaultOptions, {
                remote: {
                    events: {
                        extendParams: function (prevValues) {
                            let variables = cacheManager.getVariables(selectId);
                            let customExtendParamsEvent = zmnUtil.isObject(variables) ? variables.extendParamsEvent : null;
                            let customExtendParams = zmnUtil.isFunction(customExtendParamsEvent) ? customExtendParamsEvent(prevValues) : {};

                            let customExtendParamsEvents = zmnUtil.isObject(variables) ? variables.extendParamsEvents : null;
                            if (zmnUtil.isArray(customExtendParamsEvents) && customExtendParamsEvents.length > 0) {
                                for (let j = 0; j < customExtendParamsEvents.length; j++) {
                                    let otherCustomExtendParamsEvent = customExtendParamsEvents[j];
                                    let otherCustomExtendParams = zmnUtil.isFunction(otherCustomExtendParamsEvent) ? otherCustomExtendParamsEvent(prevValues) : {};
                                    customExtendParams = getMergedObj(otherCustomExtendParams, customExtendParams);
                                }
                            }

                            let defaultExtendParamsEvent = zmnUtil.isObject(variables) ? variables.defaultExtendParamsEvent : null;
                            return zmnUtil.isFunction(defaultExtendParamsEvent) ? defaultExtendParamsEvent(prevValues, customExtendParams) : customExtendParams;
                        }
                    }
                }
            });
            return newOptions;
        },
        /**
         * 创建xmSelect对象
         * @param selectId
         * @param options
         * @return xmSelect对象
         */
        createXmSelect: function (selectId, options) {
            let newOptions = getMergedObj(options, this.options);
            if (zmnUtil.isEmptyNull(newOptions.name)) {
                newOptions.name = selectId;
            }
            return xmSelectManager.create(selectId, newOptions);
        },
        /**
         * 创建多个xmSelect对象（支持联动）
         * @param optionsMap 配置Map，格式：{selectId: options}
         * @return xmSelect对象Map，格式：{selectId: xmSelect对象}
         */
        createXmSelects: function (optionsMap) {
            let selectMap = {};
            let selectIds = Object.keys(optionsMap);
            for (let i = 0; i < selectIds.length; i++) {
                let selectId = selectIds[i];
                let options = optionsMap[selectId];
                let changedEvent = getField(options, "events.changed");
                if (zmnUtil.isFunction(changedEvent)) {
                    delete options.events.changed;
                }
                let validateEvent = getField(options, "remote.events.validate");
                if (zmnUtil.isFunction(validateEvent)) {
                    delete options.remote.events.validate;
                }
                let newOptions = getMergedObj(options, {
                    remote: {
                        events: {
                            validate: function (searchValue) {
                                if (zmnUtil.isFunction(validateEvent)) {
                                    return validateEvent(searchValue) === true;
                                }
                                if (i > 0) {
                                    let prevSelectId = selectIds[i - 1];
                                    let prevSelect = selectMap[prevSelectId];
                                    let prevValues = prevSelect.getValue("value");
                                    return prevValues.length > 0;
                                }
                                return true
                            }
                        }
                    },
                    events: {
                        changed: function (values) {
                            if (values.length == 0) {
                                //清空所有下级下拉框
                                xmSelectManager.clearData(i + 1, selectIds, selectMap);
                            } else if (i < selectIds.length - 1) {
                                let oldValues = cacheManager.getCurrentValues(selectId);
                                let isRefresh = !compareArray(oldValues, values);
                                if (isRefresh) {
                                    //刷新下级下拉框
                                    let nextSelectId = selectIds[i + 1];
                                    let nextOptions = cacheManager.getOptions(nextSelectId);
                                    //下级组件为搜索下拉框时，只清空，不重载
                                    if (nextOptions.remote.search == true) {
                                        let variables = cacheManager.getVariables(nextSelectId);
                                        if (!zmnUtil.isObject(variables)) {
                                            variables = {}
                                        }
                                        variables.prevValues = values;
                                        cacheManager.setVariables(nextSelectId, variables);
                                        xmSelectManager.clearData(i + 1, selectIds, selectMap);
                                    } else {
                                        xmSelectManager.reload(nextSelectId, {}, values);
                                        //清空所有下下级下拉框
                                        xmSelectManager.clearData(i + 2, selectIds, selectMap);
                                    }
                                }
                            }
                            cacheManager.setCurrentValues(selectId, values);
                            if (zmnUtil.isFunction(changedEvent)) {
                                changedEvent(values);
                            }
                        }
                    }
                });
                if (cacheManager.existSelect(selectId)) {
                    selectMap[selectId] = xmSelectManager.update(selectId, newOptions);
                } else {
                    selectMap[selectId] = zmnSelect.createXmSelect(selectId, newOptions);
                }
            }
            return selectMap;
        },
        /**
         * 删除已创建的xmSelect
         * @param selectId
         */
        deleteXmSelect: function (selectId) {
            cacheManager.delSelect(selectId);
        },
        /**
         * 批量删除已创建的xmSelect
         * @param selectIds 字符串数组
         */
        deleteXmSelects: function (selectIds) {
            for (let i = 0; i < selectIds.length; i++) {
                this.deleteXmSelect(selectIds[i]);
            }
        },
        /**
         * 重载xmSelect的数据
         * @param selectId
         * @param options
         */
        reloadXmSelect: function (selectId, options) {
            let $id = $('#'+selectId);
            if($id.length == 0){
                return;
            }
            xmSelectManager.reload(selectId, options)
        },
        /**
         * 重载多个xmSelect的数据
         * @param optionsMap 配置Map，格式：{selectId: options}
         */
        reloadXmSelects: function (optionsMap) {
            let selectIds = Object.keys(optionsMap);
            for (let i = 0; i < selectIds.length; i++) {
                let selectId = selectIds[i];
                let options = optionsMap[selectId];
                let isReload = zmnUtil.isObject(options.events) && zmnUtil.isFunction(options.events.reload) ? options.events.reload(options) : options.isReload;
                let prevValues = null;
                //针对多级下拉框时，如果上级下拉框无选中值，则不重载当前下拉框
                if (i > 0) {
                    //传递上级下拉框的选中值
                    let prevId = selectIds[i - 1];
                    let preOptions = optionsMap[prevId];
                    let values = preOptions.selectedValues;
                    // let isForceReload = preOptions.isForceReload || false;
                    if ((zmnUtil.isArray(values) && values.length > 0) || (!zmnUtil.isArray(values) && zmnUtil.isNotEmptyNull(values))) {
                        prevValues = values;
                    } else {
                        isReload = false;
                    }
                }
                if (isReload) {
                    xmSelectManager.reload(selectId, options, prevValues);
                }
            }
        },
        /**
         * 获取已创建的xmSelect对象
         * @param selectId
         * @return {*}
         */
        getXmSelect: function (selectId) {
            return zmnUtil.isNotEmptyNull(selectId) ? cacheManager.getSelect(selectId) : null;
        },
        /**
         * 获取已创建的下拉框配置
         * @param selectId
         * @return {*}
         */
        getOptions: function (selectId) {
            return cacheManager.getOptions(selectId);
        },
        /**
         * 更新已创建的下拉框配置
         * @param selectId
         * @param options
         */
        updateOptions: function (selectId, options) {
            xmSelectManager.update(selectId, options);
            let extendParamsEvent = getField(options, "remote.events.extendParams");
            if (zmnUtil.isFunction(extendParamsEvent)) {
                this.updateExtendParamsEvent(selectId, extendParamsEvent);
            }
        },
        /**
         * 更新扩展请求参数事件
         * @param selectId
         * @param extendParamsEvent
         * @param clearAll 清理所有缓存的扩展请求参数事件，默认为true
         */
        updateExtendParamsEvent: function (selectId, extendParamsEvent, clearAll = true) {
            let variables = cacheManager.getVariables(selectId);
            if (!zmnUtil.isObject(variables)) {
                variables = {}
            }
            variables.extendParamsEvent = extendParamsEvent;
            //清空其他扩展请求参数
            if (clearAll === true && zmnUtil.isArray(variables.extendParamsEvents)) {
                variables.extendParamsEvents = [];
            }
            cacheManager.setVariables(selectId, variables);
        },
        /**
         * 追加扩展请求参数事件
         * @param selectId
         * @param extendParamsEvent
         */
        appendExtendParamsEvent: function (selectId, extendParamsEvent) {
            let variables = cacheManager.getVariables(selectId);
            if (!zmnUtil.isObject(variables)) {
                variables = {}
            }

            if (zmnUtil.isArray(variables.extendParamsEvents)) {
                //排除重复函数
                let isPush = true;
                variables.extendParamsEvents.forEach(item => {
                    if (item.toString() == extendParamsEvent.toString()) {
                        isPush = false
                    }
                });
                if (isPush) {
                    variables.extendParamsEvents.push(extendParamsEvent);
                }
            } else {
                variables.extendParamsEvents = [extendParamsEvent];
            }
            cacheManager.setVariables(selectId, variables);
        },
        /**
         * 更新默认的扩展请求参数事件
         * @param selectId
         * @param defaultExtendParamsEvent
         */
        updateDefaultExtendParamsEvent: function (selectId, defaultExtendParamsEvent) {
            let variables = cacheManager.getVariables(selectId);
            if (!zmnUtil.isObject(variables)) {
                variables = {}
            }
            variables.defaultExtendParamsEvent = defaultExtendParamsEvent;
            cacheManager.setVariables(selectId, variables);
        },
        /**
         * 单个公共下拉框
         * @param selectId
         * @param options
         * @return xmSelect对象
         */
        selectBox: function (selectId, options) {
            let optionsMap = {};
            optionsMap[selectId] = options;
            let selectMap = this.selectBoxes({
                selectKey: {
                    id: selectId,
                    sn: 1,
                }
            }, {
                selectKey: options
            }, null);
            return selectMap[selectId];
        },
        /**
         * 公共下拉框（支持级联）
         * @param selectKeyMap 格式：
         * {
         *     selectKey: {
         *         id: null, //元素ID
         *         sn: 1, //序号，从1开始
         *     }
         * }
         * @param optionsMap 格式：
         * {
         *     selectKey: options //配置
         * }
         * @param commonOptions
         * @return xmSelect对象Map，格式：{selectId: xmSelect对象}
         */
        selectBoxes: function (selectKeyMap, optionsMap, commonOptions) {
            let selectIds = selectKeyManager.getSelectIds(selectKeyMap);
            let selectIdMap = selectKeyManager.getSelectIdMap(selectKeyMap);
            optionsMap = zmnUtil.isObject(optionsMap) ? optionsMap : {};
            commonOptions = zmnUtil.isObject(commonOptions) ? commonOptions : {}

            let newOptionsMap = {};
            for (let i = 0; i < selectIds.length; i++) {
                let selectId = selectIds[i];
                if (zmnUtil.isEmptyNull(selectId)) {
                    continue;
                }
                let selectKey = selectIdMap[selectId];

                let options = zmnUtil.isObject(optionsMap[selectKey]) ? optionsMap[selectKey] : optionsMap[selectId];

                let newOptions = getMergedObj(options, commonOptions);

                newOptions.isReload = zmnUtil.isEmptyNull(newOptions.isReload) ? true : newOptions.isReload;

                if (cacheManager.existSelect(selectId)) {

                    let oldOptions = cacheManager.getOptions(selectId);

                    newOptions.isReload = true;

                    if (oldOptions.isReload === true) {
                        if (zmnUtil.isNotEmptyNull(newOptions.selectedValues)) {
                            //存在已选中值时，需要重载数据
                            newOptions.isReload = true;
                        } else if (zmnUtil.isNotEmptyNull(newOptions.searchedValue)) {
                            //存在已搜索值时，需要重载数据
                            newOptions.isReload = true;
                        } else {
                            //已重载时，不需要再次重载
                            newOptions.isReload = false;
                        }
                    }

                    let extendParamsEvent = getField(newOptions, "remote.events.extendParams");
                    if (zmnUtil.isFunction(extendParamsEvent)) {
                        let oldExtendParamsEvent = getField(oldOptions, 'remote.events.extendParams');
                        if (zmnUtil.isFunction(oldExtendParamsEvent) && oldExtendParamsEvent.toString() !== extendParamsEvent.toString()) {
                            this.appendExtendParamsEvent(selectId, extendParamsEvent);
                        }
                        delete newOptions.remote.events.extendParams;
                    }
                }

                newOptionsMap[selectId] = newOptions;
            }
            let selectMap = this.createXmSelects(newOptionsMap);
            this.reloadXmSelects(newOptionsMap);
            return selectMap;
        },
        /**
         * 单个公共搜索下拉框
         * @param selectId
         * @param options
         * @param defaultOptions
         * @return xmSelect对象
         */
        searchBox: function (selectId, options) {
            let selectMap = this.searchBoxes({
                selectKey: {
                    id: selectId,
                    sn: 1
                }
            }, {
                selectKey: options
            }, null);
            return selectMap[selectId];
        },
        /**
         * 公共搜索下拉框（支持级联）
         * @param selectKeyMap 格式：
         * {
         *     selectKey: {
         *         id: null, //元素ID
         *         sn: 1, //序号，从1开始
         *     }
         * }
         * @param optionsMap
         * @param commonOptions
         * @return xmSelect对象Map，格式：{selectId: xmSelect对象}
         */
        searchBoxes: function (selectKeyMap, optionsMap, commonOptions) {
            let newCommonOptions = getMergedObj(commonOptions, {
                tips: '-搜索-',
                remote: {
                    enable: true,
                    search: true,
                    events: {
                        validate: function (searchValue) {
                            // 不为空，且至少2个汉字/2个英文字符/2个数字
                            return zmnUtil.isNotEmptyNull(searchValue) && (/^(([\u4E00-\u9FA5]{2,})|([A-Za-z]{2,})|([0-9]{2,})).*$/.test(searchValue));
                        },
                    }
                },
                events: {
                    reload: function (options) {
                        return zmnUtil.isNotNull(options.searchedValue);
                    }
                }
            });
            return this.selectBoxes(selectKeyMap, optionsMap, newCommonOptions);
        },
        /**
         * 公共下拉框（支持多级联动）
         * @param optionsMap 配置Map，格式：{selectId: options}
         * @deprecated
         * @see zmnSelect.selectBoxes
         */
        select: function (optionsMap) {
            let selectKeyMap = {};
            Object.keys(optionsMap).forEach(function (k, i) {
                selectKeyMap[k] = {
                    id: k,
                    sn: i + 1
                };
            })
            return zmnSelect.selectBoxes(selectKeyMap, optionsMap);
        },
        /**
         * 公共搜索下拉框（支持多级联动）
         * @param optionsMap 配置Map，格式：{selectId: options}
         * @deprecated
         * @see zmnSelect.searchBoxes
         */
        search: function (optionsMap) {
            let selectKeyMap = {};
            Object.keys(optionsMap).forEach(function (k, i) {
                selectKeyMap[k] = {
                    id: k,
                    sn: i + 1
                };
            })
            return zmnSelect.searchBoxes(selectKeyMap, optionsMap);
        },
        /**
         * 获取已选中的选项值
         * @param selectId
         * @return {null|*}
         */
        getSelectedValue: function (selectId) {
            let select = zmnSelect.getXmSelect(selectId);
            if (zmnUtil.isObject(select)) {
                let currentValues = select.getValue("value");
                if(zmnUtil.isArray(currentValues) && currentValues.length > 0){
                    return currentValues;
                }
                let selectedValues = cacheManager.getSelectedValues(selectId);
                if(zmnUtil.isArray(selectedValues) && selectedValues.length > 0){
                    return selectedValues;
                }
            }
            return [];
        },
        /**
         * 获取已选中的选项文本
         * @param selectId
         * @return {null|*}
         */
        getSelectedText: function (selectId) {
            let select = zmnSelect.getXmSelect(selectId);
            if (zmnUtil.isObject(select)) {
                return select.getValue("name");
            }
            return null;
        },
        /**
         * 清除数据
         * @param selectId
         */
        clearData: function (selectId) {
            let select = zmnSelect.getXmSelect(selectId);
            if (zmnUtil.isObject(select)) {
                select.update({
                    data: []
                });
            }
        },
        clearSelectedData: function (selectId) {
            let select = zmnSelect.getXmSelect(selectId);
            if (zmnUtil.isObject(select) && zmnUtil.isFunction(select.setValue)) {
                select.setValue([]);
            }
        },
        /**
         * 搜索
         */
        triggerSearch: function (selectId, value) {
            let select = zmnSelect.getXmSelect(selectId);
            if (zmnUtil.isObject(select)) {
                xmSelectManager.triggerSearch(selectId, value);
            }
        }
    }

    let xmSelectManager = {
        convertOptions: function (selectId, options) {
            let xmSelectOptions = {
                el: '#' + selectId,
                name: zmnUtil.isNotEmptyNull(options.name) ? options.name : selectId,
                filterable: options.filterable === false ? false : true, //是否开启搜索
                autoRow: options.autoRow === false ? false : true, //选择值换行
                tips: options.tips,
                searchTips: options.searchTips,
                empty: options.emptyTips,
                radio: options.isRadio === true ? true : false,
                clickClose: options.isRadio === true && options.tree.enable === true ? true : false,
                paging: options.page.enable === true ? true : false,
                pageSize: options.page.pageSize,
                pageEmptyShow: options.page.isShowEmpty === true ? true : false, //无数据时不展示分页
                showCount: options.maxCount, //与分页配置互斥, 开启分页后, 此配置无效
                size: options.sizeModel,
                prop: options.propMap,
                on: function (data) {
                    //arr:  当前多选已选中的数据
                    let arr = data.arr;
                    //change, 此次选择变化的数据,数组
                    // let change = data.change;
                    //isAdd, 此次操作是新增还是删除
                    let isAdd = data.isAdd;

                    let values = [];

                    //单选时，如果选择树形下拉的父级节点，则选中值默认取第一个叶子节点值
                    if (options.tree.enable === true && options.isRadio === true) {
                        arr = data.change.slice(0, 1);
                    }

                    if (arr.length > 0) {
                        arr.forEach(function (vt) {
                            values.push(vt[options.propMap.value]);
                        });
                    }

                    if (zmnUtil.isFunction(options.events.changing)) {
                        options.events.changing(values);
                    }

                    //单选时，如果选择树形下拉的父级节点，则选中值默认取第一个叶子节点值
                    if (options.tree.enable === true && options.isRadio === true) {
                        return data.change.slice(0, 1);
                    }

                }
            }
            //显示模式
            xmSelectOptions.model = {
                label: {
                    type: 'block',
                    block: {
                        //最大显示数量, 0:不限制
                        showCount: zmnUtil.isInteger(options.showCount) ? options.showCount : 1,
                        //是否显示删除图标
                        showIcon: true,
                    }
                }
            }
            //工具栏
            xmSelectOptions.toolbar = {
                show: options.isRadio === false ? true : false, //只有多选时显示
                list: ['ALL', 'CLEAR', 'REVERSE'] //ALL: 全选; CLEAR: 清空; REVERSE: 反选
            }
            //树
            xmSelectOptions.tree = {
                //是否显示树状结构
                show: options.tree.enable === true ? true : false,
                //是否展示三角图标
                showFolderIcon: options.tree.showFolderIcon === false ? false : true,
                //是否显示虚线
                showLine: options.tree.showLine === false ? false : true,
                //间距
                indent: zmnUtil.isInteger(options.tree.indent) && options.tree.indent > 0 ? options.tree.indent : 20,
                //是否严格遵守父子模式
                strict: options.tree.strict === false ? false : true,
                //默认展开节点的数组, 为 true 时, 展开所有节点
                expandedKeys: zmnUtil.isArray(options.tree.expandedKeys) || options.tree.expandedKeys === true ? options.tree.expandedKeys : [],
                //懒加载开关
                lazy: options.tree.lazy === true ? true : false,
                //懒加载事件
                load: function (item, callback) {
                    //item: 点击的节点, callback: 回调函数
                    if (zmnUtil.isFunction(options.tree.events.load)) {
                        options.tree.events.load(item, callback);
                    }
                }
            }
            if (zmnUtil.isArray(options.selectedValues)) {
                cacheManager.setSelectedValues(selectId, options.selectedValues);
            } else if (zmnUtil.isNotEmptyNull(options.selectedValues)) {
                cacheManager.setSelectedValues(selectId, [options.selectedValues]);
            }
            //静态数据
            if (zmnUtil.isArray(options.data) && options.data.length > 0) {
                xmSelectOptions.data = options.data;
                let selectedData = [];
                let selectedValues = cacheManager.getSelectedValues(selectId);
                options.data.forEach(e => {
                    if(zmnUtil.isArray(selectedValues) && selectedValues.includes(e[options.propMap.value])){
                        e.selected = true
                    }
                    selectedData.push(e)
                })
                cacheManager.setSelectedData(selectId, selectedData);
            }

            //远程数据
            if (options.remote.enable === true) {
                xmSelectOptions.remoteSearch = options.remote.search;
                xmSelectOptions.delay = options.remote.delay;
                xmSelectOptions.pageRemote = options.page.remote;
                let extendParamsEvent = getField(options, "remote.events.extendParams", function () {
                    return {}
                });
                //searchValue: 搜索框的内容, 不开启搜索默认为空, callback: 回调函数, show: 当前下拉框是否展开, pageIndex: 当前第几页
                xmSelectOptions.remoteMethod = function (searchValue, callback, show, pageIndex) {
                    if (options.remote.enable != true) {
                        return;
                    }
                    // 回显
                    let selectedData = cacheManager.getSelectedData(selectId);
                    if (zmnUtil.isArray(selectedData) && selectedData.length > 0) {
                        //清空
                        cacheManager.setSelectedData(selectId, []);
                        return callback(selectedData, pageIndex);
                    }
                    if (options.remote.events.validate(searchValue) === false) {
                        return callback([], pageIndex);
                    }
                    // 提交参数
                    let params = options.remote.events.params(searchValue, options.remote.limitPermit, pageIndex);
                    let variables = cacheManager.getVariables(selectId);
                    //上级已选中值
                    let prevValues = zmnUtil.isObject(variables) && zmnUtil.isArray(variables.prevValues) ? variables.prevValues : [];
                    let extendParams = extendParamsEvent(prevValues);
                    // ajax请求
                    let requestBody = getMergedObj(params, extendParams);

                    let req = {
                        method: options.remote.method || 'post',
                        withCredentials: true,  // 支持跨域身份认证
                        url: options.remote.url
                    };
                    if (options.remote.body) {
                        if(options.remote.url.indexOf(GATEWAY_API_BASE) >=0 ){
                            req.data = {body: requestBody};
                        } else {
                            req.data = requestBody;
                        }
                    } else {
                        req.params = requestBody;
                    }
                    //console.log('axios--->', req);
                    axios(req).then(function (result) {
                        options.remote.events.success(result, callback, options.remote.events.dataMap);
                    }).catch(function (error) {
                        options.remote.events.error(error);
                    });
                }
            }
            return xmSelectOptions;
        },
        create: function (selectId, options) {
            let xmSelectOptions = this.convertOptions(selectId, options);
            let select = xmSelect.render(xmSelectOptions);
            //设置变更事件
            if (zmnUtil.isFunction(options.events.changed)) {
                select.update({
                    hide: function () {
                        let values = select.getValue("value");
                        options.events.changed(values);
                    }
                });
            }
            cacheManager.setSelect(selectId, select);
            cacheManager.setOptions(selectId, options);
            return select;
        },
        reload: function (selectId, options, prevValues) {
            let oldOptions = cacheManager.getOptions(selectId);
            let select = cacheManager.getSelect(selectId);
            options = zmnUtil.isObject(options) ? options : {}
            let searchedValue = options.searchedValue;
            if (zmnUtil.isArray(options.selectedValues)) {
                cacheManager.setSelectedValues(selectId, options.selectedValues);
            } else if (zmnUtil.isNotEmptyNull(options.selectedValues)) {
                cacheManager.setSelectedValues(selectId, [options.selectedValues]);
            }
            let newOptions = getMergedObj(options, {
                remote: {
                    events: {
                        success: function (result, callback, dataMap) {
                            let res = result.data;
                            if (result.status == 200 || res.status == 200) {
                                let dm = dataMap(res);
                                if (zmnUtil.isFunction(callback)) {
                                    if (zmnUtil.isInteger(dm.pageCount)) {
                                        callback(dm.data, dm.pageCount);
                                    } else {
                                        callback(dm.data);
                                    }
                                } else {
                                    select.update({
                                        data: dm.data,
                                        pageSize: dm.pageCount,
                                        totalSize: dm.totalCount
                                    });
                                }
                                //设置选择的值
                                let selectedValues = cacheManager.getSelectedValues(selectId);
                                if (zmnUtil.isArray(selectedValues)) {
                                    if(selectedValues.length > 0){
                                        setTimeout(function(){
                                            select.setValue(selectedValues);
                                        }, 100);
                                        cacheManager.setSelectedValues(selectId, null);
                                    }
                                } else if (zmnUtil.isNotEmptyNull(selectedValues)) {
                                    setTimeout(function(){
                                        select.setValue([selectedValues]);
                                    }, 100);
                                    cacheManager.setSelectedValues(selectId, null);
                                }
                            }
                        },
                        error: function (error) {
                            console.log(error);
                        }
                    }
                }
            }, oldOptions);
            if (newOptions.remote.enable) {
                let paramsEvent = getField(newOptions, "remote.events.params", function (searchValue, limitPermit, pageIndex) {
                    return {
                        keyword: searchValue,
                        limitPermit: limitPermit,
                    };
                });
                let params = paramsEvent(searchedValue, newOptions.remote.limitPermit, 0);

                let extendParamsEvent = getField(newOptions, "remote.events.extendParams", function () {
                    return {}
                });

                let prevValueArr;
                //缓存扩展参数值
                if (zmnUtil.isNotEmptyNull(prevValues)) {
                    if (zmnUtil.isArray(prevValues)) {
                        prevValueArr = prevValues;
                    } else {
                        prevValueArr = [prevValues];
                    }
                    let variables = cacheManager.getVariables(selectId);
                    if (!zmnUtil.isObject(variables)) {
                        variables = {}
                    }
                    variables.prevValues = prevValueArr;
                    cacheManager.setVariables(selectId, variables);
                }

                let extendParams = extendParamsEvent(prevValueArr);

                let requestBody = getMergedObj(params, extendParams);

                // 相当于$.ajax
                let req = {
                    async: false,
                    method: newOptions.remote.method || 'post',
                    withCredentials: true,  // 支持跨域身份认证
                    url: newOptions.remote.url
                };
                if (newOptions.remote.body) {
                    if(newOptions.remote.url.indexOf(GATEWAY_API_BASE) >=0 ){
                        req.data = {body: requestBody};
                    } else {
                        req.data = requestBody;
                    }
                } else {
                    req.params = requestBody;
                }
                axios(req).then(function (result) {
                    newOptions.remote.events.success(result, null, newOptions.remote.events.dataMap);
                }).catch(function (error) {
                    newOptions.remote.events.error(error);
                });
            } else if (zmnUtil.isArray(newOptions.data)) {
                select.update({
                    data: newOptions.data
                });
                if (newOptions.data.length > 0) {
                    //设置选择的值
                    let selectedValues = cacheManager.getSelectedValues(selectId);
                    if (zmnUtil.isArray(selectedValues)) {
                        if(selectedValues.length > 0){
                            select.setValue(selectedValues);
                        }
                    } else if (zmnUtil.isNotEmptyNull(selectedValues)) {
                        select.setValue([selectedValues]);
                    }
                }
            }
            return false;
        },
        update: function (selectId, options) {
            let select = cacheManager.getSelect(selectId);
            let oldOptions = cacheManager.getOptions(selectId);
            let newOptions = getMergedObj(options, oldOptions);
            let xmSelectOptions = this.convertOptions(selectId, newOptions);
            select.update(xmSelectOptions);
            //设置变更事件
            if (zmnUtil.isFunction(newOptions.events.changed)) {
                select.update({
                    hide: function () {
                        let values = select.getValue("value");
                        newOptions.events.changed(values);
                    }
                });
            }
            cacheManager.setSelect(selectId, select);
            cacheManager.setOptions(selectId, newOptions);
            return select;
        },
        clearData: function (startIndex, selectIds, selectMap) {
            for (let i = startIndex; i < selectIds.length; i++) {
                let nextSelectId = selectIds[i];
                let nextSelect = selectMap[nextSelectId];
                nextSelect.update({data: []});
            }
        },
        /**
         * 触发xmSelect的远程搜索功能
         * @param selectId
         */
        triggerSearch: function (selectId, value = '', defaultValue = 'test') {
            let evt = document.createEvent('HTMLEvents')
            evt.initEvent('input', true, true)
            //默认值触发远程搜索方法
            $('#' + selectId).find('.xm-search-input').val(defaultValue)
            $('#' + selectId).find('.xm-search-input').get(0).dispatchEvent(evt)
            //远程搜索方法真实搜索的内容
            $('#' + selectId).find('.xm-search-input').val(value);
            $('#' + selectId).find('.xm-search-input').get(0).dispatchEvent(evt)
        }
    }

    let selectKeyManager = {
        /**
         * 获取元素ID键值对
         * @param selectIdMap 格式：
         * {
         *     selectKey: {
         *         id: null, //元素ID
         *         sn: 1, //序号，从1开始
         *     }
         * }
         */
        getSelectIdMap: function (selectKeyMap) {
            selectKeyMap = zmnUtil.isObject(selectKeyMap) ? selectKeyMap : {};
            let selectIdMap = {};
            for (const [key, value] of Object.entries(selectKeyMap)) {
                if (zmnUtil.isNotNull(value.id)) {
                    selectIdMap[value.id] = key
                }
            }
            return selectIdMap;
        },
        /**
         * 提取元素ID集合
         * @param selectIdMap 格式：
         * {
         *     selectKey: {
         *         id: null, //元素ID
         *         sn: 1, //序号，从1开始
         *     }
         * }
         */
        getSelectIds: function (selectKeyMap) {
            selectKeyMap = zmnUtil.isObject(selectKeyMap) ? selectKeyMap : {};
            return Object.values(selectKeyMap).filter(v => zmnUtil.isNotNull(v.id)).sort((v1, v2) => v1.sn - v2.sn).map(v => v.id)
        },

    }

    // 缓存管理器
    let cacheManager = {
        /**
         * 设置缓存
         * @param key 键
         * @param fieldName 属性名
         * @param fieldValue 属性值
         */
        setCache: function (key, fieldName, fieldValue) {
            if (!zmnSelectCache.hasOwnProperty(key)) {
                zmnSelectCache[key] = {};
            }
            zmnSelectCache[key][fieldName] = fieldValue;
        },
        /**
         * 获取缓存
         * @param key 键
         * @param fieldName 属性名
         * @return {*}
         */
        getCache: function (key, fieldName) {
            let cache = zmnSelectCache[key];
            return zmnUtil.isObject(cache) ? cache[fieldName] : {};
        },
        getKey: function (id) {
            return '#' + id;
        },
        existSelect: function (id) {
            let select = this.getSelect(id);
            return zmnUtil.isObject(select) && Object.keys(select).length > 0;
        },
        /**
         * 设置配置
         * @param selectId
         * @param options
         */
        setOptions: function (id, options) {
            let key = this.getKey(id);
            this.setCache(key, 'options', options);
        },
        /**
         * 获取配置
         * @param selectId
         * @return {null|*}
         */
        getOptions: function (id) {
            let key = this.getKey(id);
            return this.getCache(key, 'options');
        },
        /**
         * 设置下拉实例
         * @param selectId
         * @param select
         */
        setSelect: function (id, select) {
            let key = this.getKey(id);
            this.setCache(key, "select", select)
        },
        /**
         * 获取下拉实例
         * @param selectId
         * @return {null|*}
         */
        getSelect: function (id) {
            let key = this.getKey(id);
            return this.getCache(key, "select");
        },
        delSelect: function (id) {
            let key = this.getKey(id);
            delete zmnSelectCache[key];
        },
        /**
         * 设置中间变量
         * @param selectId
         * @param params
         */
        setVariables: function (id, variables) {
            let key = this.getKey(id);
            this.setCache(key, 'variables', variables);
        },
        /**
         * 获取中间变量
         * @param selectId
         * @return {*}
         */
        getVariables: function (id) {
            let key = this.getKey(id);
            return this.getCache(key, 'variables')
        },
        /**
         * 设置已选中值（用于回显）
         * @param id
         * @param values
         */
        setSelectedValues: function (id, values) {
            let key = this.getKey(id);
            this.setCache(key, "selectedValues", values);
        },
        getSelectedValues: function (id) {
            let key = this.getKey(id);
            return this.getCache(key, "selectedValues");
        },
        /**
         * 设置已选中的数据集合（用于回显）
         * @param id
         * @param data
         */
        setSelectedData: function (id, data) {
            let key = this.getKey(id);
            this.setCache(key, "selectedData", data);
        },
        getSelectedData: function (id) {
            let key = this.getKey(id);
            return this.getCache(key, "selectedData");
        },
        /**
         * 设置当前值
         * @param id
         */
        setCurrentValues: function (id, values) {
            let key = this.getKey(id);
            this.setCache(key, "currentValues", values);
        },
        getCurrentValues: function (id) {
            let key = this.getKey(id);
            return this.getCache(key, "currentValues");
        }
    }

    let selectMethods = {
        selectProductType: function (selectId, options) {
            let $id = $('#' + selectId);
            if ($id.length == 0) {
                return;
            }
            let newOptions = zmnSelect.mergeOptions(selectId, options, {
                tips: "-选择-",
                isRadio: false,
                selectedValues: [1],
                data: [
                    {
                        value: 1,
                        text: "前台产品"
                    }, {
                        value: 2,
                        text: "后台产品"
                    }
                ]
            })
            return zmnSelect.selectBox(selectId, newOptions);
        },
        /**
         * 工单类型
         * @param selectId
         * @param options
         * @return xmSelect对象
         */
        selectWorkType: function (selectId, options) {
            let $id = $('#' + selectId);
            if ($id.length == 0) {
                return;
            }
            let newOptions = zmnSelect.mergeOptions(selectId, options, {
                tips: "-选择类型-",
                isRadio: false,
                data: [
                    {
                        value: 1,
                        text: "新单"
                    }, {
                        value: 2,
                        text: "返修单"
                    }, {
                        value: 3,
                        text: "退款单"
                    }, {
                        value: 4,
                        text: "赔偿单"
                    }
                ]
            })
            return zmnSelect.selectBox(selectId, newOptions);
        },
        /**
         * 上门类型
         * @param selectId
         * @param options
         * @return xmSelect对象
         */
        selectVisitType: function (selectId, options) {
            let $id = $('#' + selectId);
            if ($id.length == 0) {
                return;
            }
            let newOptions = zmnSelect.mergeOptions(selectId, options, {
                tips: "-选择类型-",
                isRadio: true,
                data: [
                    {
                        value: 1,
                        text: "拉修"
                    }, {
                        value: 2,
                        text: "待件"
                    }, {
                        value: 3,
                        text: "其他"
                    }
                ]
            })
            return zmnSelect.selectBox(selectId, newOptions);
        },
        /**
         * 工单类型
         * @param selectId
         * @param options
         * @return xmSelect对象
         */
        selectVisitStatus: function (selectId, options) {
            let $id = $('#' + selectId);
            if ($id.length == 0) {
                return;
            }
            let newOptions = zmnSelect.mergeOptions(selectId, options, {
                tips: "-选择状态-",
                isRadio: true,
                data: [
                    {
                        value: 10,
                        text: "已提交"
                    }, {
                        value: 20,
                        text: "已出发"
                    }, {
                        value: 30,
                        text: "已上门"
                    }, {
                        value: 40,
                        text: "已取消"
                    }
                ]
            })
            return zmnSelect.selectBox(selectId, newOptions);
        },
        /**
         * 工单状态结果
         * @param selectId
         * @param options
         * @return xmSelect对象
         */
        selectWorkResultStatus: function (selectId, options) {
            let $id = $('#' + selectId);
            if ($id.length == 0) {
                return;
            }
            let newOptions = zmnSelect.mergeOptions(selectId, options, {
                tips: "-选择结果-",
                isRadio: true,
                data: [
                    {
                        value: 1,
                        text: "进行中"
                    }, {
                        value: 2,
                        text: "成功"
                    }, {
                        value: 4,
                        text: "弃单"
                    }, {
                        value: 3,
                        text: "失败"
                    }
                ]
            })
            return zmnSelect.selectBox(selectId, newOptions);
        },
        /**
         * 工单状态结果
         * @param selectId
         * @param options
         * @return xmSelect对象
         */
        selectWorkCancelResultStatus: function (selectId, options) {
            let $id = $('#' + selectId);
            if ($id.length == 0) {
                return;
            }
            let newOptions = zmnSelect.mergeOptions(selectId, options, {
                tips: "-选择结果-",
                isRadio: true,
                data: [
                    {
                        value: 4,
                        text: "弃单"
                    }, {
                        value: 3,
                        text: "失败"
                    }
                ]
            })
            return zmnSelect.selectBox(selectId, newOptions);
        },
        /**
         * 工单取消时可选状态
         * @param selectId
         * @param options
         * @return xmSelect对象
         */
        selectWorkCancelStatus: function (selectId, options) {
            let $id = $('#' + selectId);
            if ($id.length == 0) {
                return;
            }
            let newOptions = zmnSelect.mergeOptions(selectId, options, {
                tips: "-选择状态-",
                isRadio: false,
                data: [
                    {
                        value: 11,
                        text: "已录入"
                    }, {
                        value: 31,
                        text: "已确认"
                    }, {
                        value: 34,
                        text: "已分单"
                    }, {
                        value: 41,
                        text: "已派单"
                    }, {
                        value: 51,
                        text: "已领单"
                    }, {
                        value: 61,
                        text: "已上门"
                    }
                ]
            })
            return zmnSelect.selectBox(selectId, newOptions);
        },
        /**
         * 工单状态
         * @param selectId
         * @param options
         * @return xmSelect对象
         */
        selectWorkStatus: function (selectId, options) {
            let $id = $('#' + selectId);
            if ($id.length == 0) {
                return;
            }
            let newOptions = zmnSelect.mergeOptions(selectId, options, {
                tips: "-选择状态-",
                isRadio: false,
                data: [
                    {
                        value: 11,
                        text: "已录入"
                    }, {
                        value: 31,
                        text: "已确认"
                    }, {
                        value: 34,
                        text: "已分单"
                    }, {
                        value: 41,
                        text: "已派单"
                    }, {
                        value: 51,
                        text: "已领单"
                    }, {
                        value: 61,
                        text: "已上门"
                    }, {
                        value: 66,
                        text: "服务完成"
                    }, {
                        value: 71,
                        text: "已完成"
                    }, {
                        value: 81,
                        text: "已收单"
                    }, {
                        value: 91,
                        text: "已算账"
                    }
                ]
            })
            return zmnSelect.selectBox(selectId, newOptions);
        },
        /**
         * 快递状态
         * @param selectId
         * @param options
         * @return xmSelect对象
         */
        selectPostStatus: function (selectId, options) {
            let $id = $('#' + selectId);
            if ($id.length == 0) {
                return;
            }
            let newOptions = zmnSelect.mergeOptions(selectId, options, {
                tips: "-选择状态-",
                isRadio: false,
                data: [
                    {
                        value: 1,
                        text: "已揽件"
                    }, {
                        value: 2,
                        text: "派件中"
                    }, {
                        value: 3,
                        text: "运输中"
                    }, {
                        value: 4,
                        text: "已签收"
                    }, {
                        value: 5,
                        text: "签收异常"
                    }, {
                        value: 6,
                        text: "退回"
                    }, {
                        value: 7,
                        text: "异常"
                    }
                ]
            })
            return zmnSelect.selectBox(selectId, newOptions);
        },
        /**
         * 有or无
         * @param selectId
         * @param options
         * @return xmSelect对象
         */
        selectHasOrNoStatus: function (selectId, options) {
            let $id = $('#' + selectId);
            if ($id.length == 0) {
                return;
            }
            let newOptions = zmnSelect.mergeOptions(selectId, options, {
                tips: "-选择-",
                isRadio: true,
                data: [
                    {
                        value: 1,
                        text: "无"
                    }, {
                        value: 2,
                        text: "有"
                    }
                ]
            })
            return zmnSelect.selectBox(selectId, newOptions);
        },
        /**
         * 1：不重复 2：重复
         * @param selectId
         * @param options
         * @return xmSelect对象
         */
        selectRepeatOrNoStatus: function (selectId, options) {
            let $id = $('#' + selectId);
            if ($id.length == 0) {
                return;
            }
            let newOptions = zmnSelect.mergeOptions(selectId, options, {
                tips: "-选择-",
                isRadio: true,
                data: [
                    {
                        value: 1,
                        text: "不重复"
                    }, {
                        value: 2,
                        text: "重复"
                    }
                ]
            })
            return zmnSelect.selectBox(selectId, newOptions);
        },
        /**
         * 订单操作
         * @param selectId
         * @param options
         * @return xmSelect对象
         */
        selectWorkOperateType: function (selectId, options) {
            let $id = $('#' + selectId);
            if ($id.length == 0) {
                return;
            }
            let newOptions = zmnSelect.mergeOptions(selectId, options, {
                tips: "-选择-",
                isRadio: true,
                data: [
                    {
                        value: 1,
                        text: "录入"
                    }, {
                        value: 2,
                        text: "确认"
                    }, {
                        value: 4,
                        text: "派单"
                    }, {
                        value: 8,
                        text: "收单"
                    }, {
                        value: 13,
                        text: "回访"
                    }, {
                        value: 16,
                        text: "取消"
                    }, {
                        value: 505,
                        text: "跟单"
                    }
                ]
            })
            return zmnSelect.selectBox(selectId, newOptions);
        },
        /**
         * 支付状态
         * @param selectId
         * @param options
         * @return xmSelect对象
         */
        selectOrderPayStatus: function (selectId, options) {
            let $id = $('#' + selectId);
            if ($id.length == 0) {
                return;
            }
            let newOptions = zmnSelect.mergeOptions(selectId, options, {
                tips: "-选择-",
                isRadio: true,
                data: [
                    {
                        value: 1,
                        text: "未支付"
                    }, {
                        value: 2,
                        text: "支付中"
                    }, {
                        value: 3,
                        text: "部分支付"
                    }, {
                        value: 4,
                        text: "已支付"
                    }, {
                        value: 12,
                        text: "退款中"
                    }, {
                        value: 13,
                        text: "部分退款"
                    }, {
                        value: 14,
                        text: "已退款"
                    }, {
                        value: 15,
                        text: "退款失败"
                    }, {
                        value: 16,
                        text: "退款异常"
                    }
                ]
            })
            return zmnSelect.selectBox(selectId, newOptions);
        },
        /**
         * 参与报价人类型
         * @param selectId
         * @param options
         * @return xmSelect对象
         */
        selectPartakeQuotationType: function (selectId, options) {
            let $id = $('#' + selectId);
            if ($id.length == 0) {
                return;
            }
            let newOptions = zmnSelect.mergeOptions(selectId, options, {
                tips: "-选择-",
                isRadio: true,
                data: [
                    {
                        value: 1,
                        text: "系统报价"
                    }, {
                        value: 2,
                        text: "后台报价"
                    }, {
                        value: 3,
                        text: "工程师报价"
                    }, {
                        value: 4,
                        text: "用户报价"
                    }, {
                        value: 6,
                        text: "服务商报价"
                    }
                ]
            })
            return zmnSelect.selectBox(selectId, newOptions);
        },
        /**
         * 其它报价人类型
         * @param selectId
         * @param options
         * @return xmSelect对象
         */
        selectQuotationType: function (selectId, options) {
            let $id = $('#' + selectId);
            if ($id.length == 0) {
                return;
            }
            let newOptions = zmnSelect.mergeOptions(selectId, options, {
                tips: "-选择-",
                isRadio: true,
                data: [
                    {
                        value: 1,
                        text: "系统报价"
                    }, {
                        value: 2,
                        text: "后台报价"
                    }, {
                        value: 3,
                        text: "工程师报价"
                    }, {
                        value: 4,
                        text: "用户报价"
                    }, {
                        value: 6,
                        text: "服务商报价"
                    }, {
                        value: 0,
                        text: "其他报价"
                    }
                ]
            })
            return zmnSelect.selectBox(selectId, newOptions);
        },
        /**
         * 退款审核
         * @param selectId
         * @param options
         * @return xmSelect对象
         */
        selectRefundWorkReviewStatus: function (selectId, options) {
            let $id = $('#' + selectId);
            if ($id.length == 0) {
                return;
            }
            let newOptions = zmnSelect.mergeOptions(selectId, options, {
                tips: "-选择-",
                isRadio: false,
                data: [
                    {
                        value: 0,
                        text: "不需审核"
                    },
                    {
                        value: 1,
                        text: "审核中"
                    }, {
                        value: 2,
                        text: "已通过"
                    }, {
                        value: 3,
                        text: "未通过"
                    }
                ]
            })
            return zmnSelect.selectBox(selectId, newOptions);
        },
        /**
         * 赔偿审核
         * @param selectId
         * @param options
         * @return xmSelect对象
         */
        selectCompensateWorkReviewStatusList: function (selectId, options) {
            let $id = $('#' + selectId);
            if ($id.length == 0) {
                return;
            }
            let newOptions = zmnSelect.mergeOptions(selectId, options, {
                tips: "-选择-",
                isRadio: false,
                data: [
                    {
                        value: 1,
                        text: "审核中"
                    }, {
                        value: 2,
                        text: "已通过"
                    }, {
                        value: 3,
                        text: "未通过"
                    }
                ]
            })
            return zmnSelect.selectBox(selectId, newOptions);
        },
        /**
         * 配件报销
         * @param selectId
         * @param options
         * @return xmSelect对象
         */
        selectPartReimburseStatusList: function (selectId, options) {
            let $id = $('#' + selectId);
            if ($id.length == 0) {
                return;
            }
            let newOptions = zmnSelect.mergeOptions(selectId, options, {
                tips: "-选择-",
                isRadio: true,
                data: [
                    {
                        value: 1,
                        text: "无需报销"
                    }, {
                        value: 2,
                        text: "待报销"
                    }, {
                        value: 4,
                        text: "报销失败"
                    }, {
                        value: 3,
                        text: "报销成功"
                    }, {
                        value: 5,
                        text: "不予报销"
                    }
                ]
            })
            return zmnSelect.selectBox(selectId, newOptions);
        },
        /**
         * 通用状态下拉框
         * @param selectId
         * @param options
         * @return xmSelect对象
         */
        selectStatus: function (selectId, options) {
            let newOptions = zmnSelect.mergeOptions(selectId, options, {
                data: [
                    {
                        value: 2,
                        text: "启用"
                    }, {
                        value: 1,
                        text: "禁用"
                    }
                ],
            })
            return zmnSelect.selectBox(selectId, newOptions);
        },
        /**
         * 责任归属
         * @param selectId
         * @param options
         * @return xmSelect对象
         */
        selectLiableType: function (selectId, options) {
            let newOptions = zmnSelect.mergeOptions(selectId, options, {
                data: [
                    {
                        value: 1,
                        text: "原工程师"
                    }, {
                        value: 2,
                        text: "当前工程师"
                    }
                ],
            })
            return zmnSelect.selectBox(selectId, newOptions);
        },
        /**
         * 退款方式
         * @param selectId
         * @param options
         * @return xmSelect对象
         */
        selectRefundType: function (selectId, options) {
            let newOptions = zmnSelect.mergeOptions(selectId, options, {
                isRadio: true,
                data: [
                    {
                        value: 1,
                        text: "原路退款"
                    }, {
                        value: 2,
                        text: "人工退款"
                    }
                ],
            })
            return zmnSelect.selectBox(selectId, newOptions);
        },
    }

    let searchMethods = {
        /**
         * 品牌
         * @param selectId
         * @param options
         */
        selectBrandList: function (selectId, options) {
            let $id = $('#' + selectId);
            if ($id.length == 0) {
                return;
            }
            let newOptions = zmnSelect.mergeOptions(selectId, options, {
                isRadio: true,
                propMap: {
                    name: "text",   //显示值
                    value: "value"  //选中值
                },
                remote: {
                    enable: true,
                    search: true, //自动请求标识：true-初始化完成后自动请求；false-不自动请求
                    method: 'get',
                    body: false,
                    url: OMS_BASE_URL + '/common/listBrand.action'
                }
            });
            console.log(newOptions);
            return zmnSelect.selectBox(selectId, newOptions);
        },
        /**
         * 取消缘由
         * @param selectId
         * @param options
         */
        selectCancelReasonList: function (selectId, options) {
            let $id = $('#' + selectId);
            if ($id.length == 0) {
                return;
            }
            let newOptions = zmnSelect.mergeOptions(selectId, options, {
                propMap: {
                    name: "text",   //显示值
                    value: "value"  //选中值
                },
                remote: {
                    enable: true,
                    //search: true, //自动请求标识：true-初始化完成后自动请求；false-不自动请求
                    method: 'get',
                    body: false,
                    url: OMS_BASE_URL + '/common/cancelReason/list.action'
                }
            });
            console.log(newOptions);
            return zmnSelect.selectBox(selectId, newOptions);
        },
        /**
         * 用户层级
         * @param selectId
         * @param options
         */
        selectUserLevelList: function (selectId, options) {
            let $id = $('#' + selectId);
            if ($id.length == 0) {
                return;
            }
            let newOptions = zmnSelect.mergeOptions(selectId, options, {
                isRadio: true,
                propMap: {
                    name: "text",   //显示值
                    value: "value"  //选中值
                },
                remote: {
                    enable: true,
                    //search: true, //自动请求标识：true-初始化完成后自动请求；false-不自动请求
                    method: 'get',
                    body: false,
                    url: OMS_BASE_URL + '/common/listUserLevel.action'
                }
            });
            console.log(newOptions);
            return zmnSelect.selectBox(selectId, newOptions);
        },
        /**
         * 工单标记
         * @param selectId
         * @param options
         */
        selectOrderWorkTagList: function (selectId, options) {
            let $id = $('#' + selectId);
            if ($id.length == 0) {
                return;
            }
            let newOptions = zmnSelect.mergeOptions(selectId, options, {
                propMap: {
                    name: "tagName",   //显示值
                    value: "id"  //选中值
                },
                remote: {
                    enable: true,
                    //search: true, //自动请求标识：true-初始化完成后自动请求；false-不自动请求
                    url: OMS_BASE_URL + '/common/ordertag/listPage',
                    events: {
                        params: function (searchValue, limitPermit, pageIndex) {
                            let result = {
                                keyWord: searchValue || null,
                            };
                            return result;
                        }
                    }
                }
            });
            console.log(newOptions);
            return zmnSelect.selectBox(selectId, newOptions);
        },
        /**
         * 1级产品分类下拉框
         * @param selectId
         * @param options
         * 附加参数：
         * {
         *     remote:{
         *         events:{
         *             extendParams: function(){
         *                return {
         *                  "servCategoryId": null, //类型（必填）：Integer类型；
         *                  "categIds": null, //类型（必填）：Integer类型；
         *                  "showType": null, //类型（必填）：Integer类型，1表示后台，2表示前台；
         *                }
         *             }
         *         }
         *     }
         * }
         * @return {xmSelect对象}
         */
        selectProductList: function (selectId, options) {
            let $id = $('#' + selectId);
            if ($id.length == 0) {
                return;
            }
            let newOptions = zmnSelect.mergeOptions(selectId, options, {
                tips: "-选择产品-",
                propMap: {
                    name: "productName",
                    value: "productId"
                },
                remote: {
                    enable: true,
                    search: true,
                    url: GATEWAY_API_BASE + '/product/api/product/listBaseByQuery',
                    events: {
                        params: function(searchValue, limitPermit, pageIndex){
                            let result = {
                                keyWord: searchValue || null,
                            };
                            return {
                                query: result,
                                limitPermit: limitPermit
                            };
                        },
                        extendParams: function (prevValues, newExtendParams) {
                            console.log(prevValues, newExtendParams);
                            return {
                                query: $.extend(true, {}, {
                                    showType: 1,
                                }, newExtendParams)
                            };
                        }
                    }
                }
            });
            console.log(newOptions);
            return zmnSelect.selectBox(selectId, newOptions);
        },
        /**
         * 网格查询
         * @param selectId
         * @param options
         */
        selectGmsGrid: function (selectId, options) {
            let $id = $('#' + selectId);
            if ($id.length == 0) {
                return;
            }
            let newOptions = zmnSelect.mergeOptions(selectId, options, {
                propMap: {
                    name: "gridName",   //显示值
                    value: "gridId"  //选中值
                },
                remote: {
                    enable: true,
                    search: false, //自动请求标识：true-初始化完成后自动请求；false-不自动请求
                    url: OMS_BASE_URL + '/area/listPageGrid',
                    events: {
                        params: function (searchValue, limitPermit, pageIndex) {
                            let result = {
                                gridName: searchValue || null,
                            };
                            if (options.page && options.page.enable === true) {
                                result.pageIndex = pageIndex;
                                result.pageSize = options.page.pageSize;
                            }
                            return result;
                        },
                        dataMap: function (resultData) {
                            let result = {
                                data: resultData.data.data || [],
                            }
                            if (options.page && options.page.enable === true) {
                                result.pageSize = options.page.pageSize;
                                result.totalCount = resultData.data.count;
                                if (zmnUtil.isInteger(result.totalCount) && zmnUtil.isInteger(result.pageSize) && result.pageSize > 0) {
                                    if (result.totalCount % result.pageSize === 0) {
                                        result.pageCount = parseInt(result.totalCount / result.pageSize);
                                    } else {
                                        result.pageCount = parseInt(result.totalCount / result.pageSize) + 1;
                                    }
                                    result.totalSize = result.pageCount;
                                }
                            }

                            // 名称加上删除
                            result.data.forEach(function (item) {
                                if (item.validStatus == 2) {
                                    item.gridName = item.gridName + '(删除)';
                                }
                            });
                            return result;
                        }
                    }
                }
            });
            console.log(newOptions);
            return zmnSelect.selectBox(selectId, newOptions);
        },
        /**
         * 标记分类
         * @param selectId
         * @param options
         */
        selectConfOrderTagCategory: function (selectId, options) {
            let select = $('#'+selectId);
            if(!select){
                return ;
            }
            let newOptions = zmnSelect.mergeOptions(selectId, options, {
                propMap: {
                    name: "categName",   //显示值
                    value: "categId"  //选中值
                },
                remote: {
                    enable: true,
                    //search: false, //自动请求标识：true-初始化完成后自动请求；false-不自动请求
                    url: OMS_BASE_URL + '/conf/ordertag/category/ajax/list?status=2',
                    events: {
                        params: function (searchValue, limitPermit, pageIndex) {
                            let result = {
                                keyWord: searchValue || null,
                            };
                            if (options.page && options.page.enable === true) {
                                result.pageIndex = pageIndex;
                                result.pageSize = options.page.pageSize;
                            }
                            return result;
                        },
                        dataMap: function (resultData) {
                            let result = {
                                data: resultData.data.data || [],
                            }
                            if (options.page && options.page.enable === true) {
                                result.pageSize = options.page.pageSize;
                                result.totalCount = resultData.data.count;
                                if (zmnUtil.isInteger(result.totalCount) && zmnUtil.isInteger(result.pageSize) && result.pageSize > 0) {
                                    if (result.totalCount % result.pageSize === 0) {
                                        result.pageCount = parseInt(result.totalCount / result.pageSize);
                                    } else {
                                        result.pageCount = parseInt(result.totalCount / result.pageSize) + 1;
                                    }
                                }
                            }
                            return result;
                        }
                    }
                }
            });
            console.log(newOptions);
            return zmnSelect.selectBox(selectId, newOptions);
        },
        /**
         * 服务商下拉框
         * @param selectId
         * @param options
         */
        selectManageCompany: function (selectId, options) {
            let select = $('#' + selectId);
            if (!select) {
                return;
            }
            let newOptions = zmnSelect.mergeOptions(selectId, options, {
                isRadio: true,
                propMap: {
                    name: "text",   //显示值
                    value: "value"  //选中值
                },
                remote: {
                    enable: true,
                    body: false,
                    search: true,
                    method: 'get',
                    url: OMS_BASE_URL + '/company/manage/company/list.action',
                    events: {
                        params: function (searchValue, limitPermit, pageIndex) {
                            let result = {
                                name: searchValue || null,
                                companyId: searchValue ? $("#companyId").val() : null,
                                plat: searchValue ? $("#plat").val() : null
                            };
                            if (options.page && options.page.enable === true) {
                                result.pageIndex = pageIndex;
                                result.pageSize = options.page.pageSize;
                            }
                            return result;
                        },
                        dataMap: function (resultData) {
                            let result = {
                                data: resultData.data || [],
                            }
                            if (options.page && options.page.enable === true) {
                                result.pageSize = options.page.pageSize;
                                result.totalCount = resultData.data.count;
                                if (zmnUtil.isInteger(result.totalCount) && zmnUtil.isInteger(result.pageSize) && result.pageSize > 0) {
                                    if (result.totalCount % result.pageSize === 0) {
                                        result.pageCount = parseInt(result.totalCount / result.pageSize);
                                    } else {
                                        result.pageCount = parseInt(result.totalCount / result.pageSize) + 1;
                                    }
                                }
                            }
                            return result;
                        }
                    }
                }
            });
            return zmnSelect.selectBox(selectId, newOptions);
        },
        /**
         * 附件分类
         * @param selectId
         * @param options
         */
        selectConfOrderAttachmentCategory: function (selectId, options) {
            let select = $('#'+selectId);
            if(!select){
                return ;
            }
            let newOptions = zmnSelect.mergeOptions(selectId, options, {
                propMap: {
                    name: "categName",   //显示值
                    value: "categId"  //选中值
                },
                remote: {
                    enable: true,
                    body: false,
                    search:true,
                    url: OMS_BASE_URL + '/conf/attachment/category/ajax/list?status=2&type='+options.type,
                    events: {
                        params: function (searchValue, limitPermit, pageIndex) {
                            let result = {
                                keyWord: searchValue || null,
                            };
                            if (options.page && options.page.enable === true) {
                                result.pageIndex = pageIndex;
                                result.pageSize = options.page.pageSize;
                            }
                            return result;
                        },
                        dataMap: function (resultData) {
                            let result = {
                                data: resultData.data.data || [],
                            }
                            if (options.page && options.page.enable === true) {
                                result.pageSize = options.page.pageSize;
                                result.totalCount = resultData.data.count;
                                if (zmnUtil.isInteger(result.totalCount) && zmnUtil.isInteger(result.pageSize) && result.pageSize > 0) {
                                    if (result.totalCount % result.pageSize === 0) {
                                        result.pageCount = parseInt(result.totalCount / result.pageSize);
                                    } else {
                                        result.pageCount = parseInt(result.totalCount / result.pageSize) + 1;
                                    }
                                }
                            }
                            return result;
                        }
                    }
                }
            });
            return zmnSelect.selectBox(selectId, newOptions);
        },
        /**
         * 改派缘由配置
         *
         * @param selectId
         * @param options
         */
        searchConfRedistributeReason: function (selectId, options) {
            let select = $('#'+selectId);
            if(!select){
                return ;
            }
            let newOptions = zmnSelect.mergeOptions(selectId, options, {
                propMap: {
                    name: "reason",   //显示值
                    value: "id"  //选中值
                },
                isRadio: true,
                remote: {
                    enable: true,
                    body: false,
                    search: true,
                    url: OMS_BASE_URL + '/conf/distributeReason/ajax/list',
                    events: {
                        params: function (searchValue, limitPermit, pageIndex) {
                            let result = {
                                keyWord: searchValue || null,
                            };
                            if (options.page && options.page.enable === true) {
                                result.pageIndex = pageIndex;
                                result.pageSize = options.page.pageSize;
                            }
                            return result;
                        },
                        dataMap: function (resultData) {
                            let result = {
                                data: resultData.data.data || [],
                            }
                            if (options.page && options.page.enable === true) {
                                result.pageSize = options.page.pageSize;
                                result.totalCount = resultData.data.count;
                                if (zmnUtil.isInteger(result.totalCount) && zmnUtil.isInteger(result.pageSize) && result.pageSize > 0) {
                                    if (result.totalCount % result.pageSize === 0) {
                                        result.pageCount = parseInt(result.totalCount / result.pageSize);
                                    } else {
                                        result.pageCount = parseInt(result.totalCount / result.pageSize) + 1;
                                    }
                                }
                            }
                            return result;
                        }
                    }
                }
            });
            return zmnSelect.selectBox(selectId, newOptions);
        },
        selectChannelTwo: function (selectId, options) {
            let newOptions = zmnSelect.mergeOptions(selectId, options, {
                remote: {
                    enable: true,
                    limitPermit: false,
                    url: GATEWAY_API_BASE+ '/channel/api/channelListRemoteService/listChannelVtByQuery',
                    events: {
                        extendParams: function (prevValues, newExtendParams) {
                            let params = $.extend(true, {}, {
                                "rank": 2,
                                parentId: zmnUtil.isArray(prevValues) && prevValues.length > 0 ? prevValues[0] : null,
                            }, newExtendParams);
                            return {
                                channelSearchDIO: params
                            };
                        }
                    },
                }
            });
            return zmnSelect.selectBox(selectId, newOptions);
        },
    }

    //对外暴露的接口
    exports('zmnOmsSelect', $.extend(true, {}, zmnSelect, selectMethods, searchMethods));

});